package com.aisile.common.swagger;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Auther:yry
 * @Date:2023/12/21 0021
 * @VERSON:1.0
 */
@Configuration
@EnableSwagger2 // 开启swagger注解支持
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class Swagger2Configuration {

    @Bean
    public Docket defulatApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("1.0")
                .select()
                // 指定Controller扫描的包路径
                .apis(RequestHandlerSelectors.basePackage("com.aisile"))
                // 展示的路径
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        Contact contact = new Contact("aisile","www.aisile.com.cn","aisile@163.com");
        return new ApiInfoBuilder()
                .title("爱思乐头条API文档")
                .description("这是一个爱思乐头条项目的API文档")
                .version("v1.0.1")
                .contact(contact)
                .build();
    }

}
